package com.java110.mall.shop.bmo.shopSetting.impl;

import com.java110.mall.shop.bmo.shopSetting.IGetShopSettingBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.intf.shop.IShopSettingInnerServiceSMO;
import com.java110.dto.shop.ShopSettingDto;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;

@Service("getShopSettingBMOImpl")
public class GetShopSettingBMOImpl implements IGetShopSettingBMO {

    @Autowired
    private IShopSettingInnerServiceSMO shopSettingInnerServiceSMOImpl;

    /**
     *
     *
     * @param  shopSettingDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(ShopSettingDto shopSettingDto) {


        int count = shopSettingInnerServiceSMOImpl.queryShopSettingsCount(shopSettingDto);

        List<ShopSettingDto> shopSettingDtos = null;
        if (count > 0) {
            shopSettingDtos = shopSettingInnerServiceSMOImpl.queryShopSettings(shopSettingDto);
        } else {
            shopSettingDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) shopSettingDto.getRow()), count, shopSettingDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
